﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LGE;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Audio;

namespace Thaneros
{
    public class Bird : Enemy
    {
        enum State
        {
            Arriving = 0,
            Locking = 1,
            Diving = 2
        };

        State state;
        int lockTime = 1000;
        double timer = 0;
        Vector2 lockDir;
        int speed = 10;

        public Bird(PlayScreen ps)
            : base(ps, Engine.Load<Texture2D>("Images\\Enemies\\bird"))
        {
            position += ps.c.position + new Vector2(1200, -400);
            state = State.Arriving;
            ps.soundBank.PlayCue("Bird_Fly");
        }

        public override void Update(GameTime gameTime)
        {
            if (!alive) return;
            switch (state)
            {
                case State.Arriving:
                    position.X -= 10;
                    if (drawPosition.X < 1200) state = State.Locking;
                    break;
                case State.Locking:
                    timer += gameTime.ElapsedGameTime.TotalMilliseconds;
                    if (timer > lockTime)
                    {
                        Vector2 temp = ps.c.position - position;
                        temp.Normalize();
                        lockDir = temp * speed;
                        state = State.Diving;
                        ps.soundBank.PlayCue("Bird_Lock");
                        ps.soundBank.PlayCue("Bird_Descent");
                    }
                    break;
                case State.Diving:
                    position += lockDir;
                    if (Collision(ps.c))
                    {
                        alive = false;
                        ps.c.HP -= 10;
                        ps.soundBank.PlayCue("Bird_HitThan");
                    }
                    else if (ps.bm.CollisionV(this, false, false) != 0)
                    {
                        alive = false;
                        ps.soundBank.PlayCue("Bird_Fall");
                    }
                    break;
                default: break;
            }
        }
    }
}
